package com.yc.jpyy.evaluation.service.impl;

import com.yc.jpyy.base.service.BaseService;
import com.yc.jpyy.base.util.PageBean;
import com.yc.jpyy.evaluation.dao.EvaluationDao;
import com.yc.jpyy.evaluation.service.EvaluationService;
import com.yc.jpyy.wxuser.dao.WxUserDao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class EvaluationServiceImpl extends BaseService implements EvaluationService {

    @Autowired
    private EvaluationDao evaluationDao;
    
    @Autowired
    private WxUserDao wxUserDao;

    @Override
    public void add(Map<String, Object> paramsMap) {
    	
        this.evaluationDao.add(paramsMap);
    }

    @Override
    public int addEvaluationForWxService(Map<String, Object> paramsMap) throws Exception {
    	
    	int num = 0 ;
    	System.out.println(num);
    	num =  wxUserDao.findWxisBlackDao(paramsMap);
    	System.out.println("num----------"+num);
	    if(num>0){
		    throw new Exception("此用户为黑名单用户");
		}	
    	this.evaluationDao.add(paramsMap);
    	return num;
    }
    @Override
    public Map<String, Object> findById(Map<String, Object> paramsMap) {
        return this.evaluationDao.findById(paramsMap);
    }

    @Override
    public PageBean findPage(Map<String, Object> paramsMap) {
        int pagenum = Integer.parseInt(paramsMap.get("pagenum").toString());
        int pagesize = Integer.parseInt(paramsMap.get("pagesize").toString());
        paramsMap.put("pagestart", (pagenum-1) * pagesize);
        //HandlerDataSource.setDataSource("bizDataSource");
        List<Map<String, Object>> list = this.evaluationDao.findPage(paramsMap);
        PageBean pageBean = new PageBean();
        pageBean.setList(list);
        // 每页几条数据，默认20条
        pageBean.setPageSize(pagesize);
        // 得到数据库中的条数
        pageBean.setAllRow(this.evaluationDao.findCount(paramsMap));
        // 当前第几页，默认第一页
        pageBean.setCurrentPage(pagenum);
        // 得到一共几页
        pageBean.setTotalPage(pageBean.getTotalPage());
        // 模仿百度分页，只显示10条数据
        pageBean.paginationTool(pagenum, pageBean.getTotalPage());
        return pageBean;
    }
}
